<?php
require './user.php';
require './function.php';
require './form.class.php';
if(!$edit=unserialize(file_get_contents($fn='./data/edit#'.$_GET['path']))) {
header('Content-Type: text/html; charset=UTF-8');
echo <<<HTML
Error：404
HTML;
exit;
}
$path=$edit['path'];
$p=floor($_GET['p']);
if($p=='-1')
 $p=floor($_GET['p2']);
if($p<=0) $p=0;
form::someinput_set($_SESSION['editset']);
//header('Content-Type: text/html; charset=UTF-8');
echo <<<HTML
<html>
<head>
<title>文件管理－保存</title>
<style type="text/css">
.big_board{background-color:#009BCE;color:#FFF;}.board_title{margin-bottom:1px;border:1px solid #09F;}
</style>
</head><body>
HTML;
/*<div class="big_board"><div class="board_title">爱特文管－路径信息</div></div>
HTML;*/
echo '<a href="index.php?path='._encode($dir=dirname($path)).'">…',substr(realpath($dir),-10,10),'</a>/',basename($path);
echo <<<HTML
<div class="big_board"><div class="board_title">文件管理－保存分段</div></div>
HTML;
$cnt=count($edit['content']);
$p0=array($p-1,$p+1,$cnt-1);
echo <<<HTML
<form action="editor.php" method="get">
<input type="hidden" name="path" value="{$_GET['path']}"/>
<select name="p"><option value="{$p0[1]}">下页</option><option value="{$p0[0]}">上页</option><option value="-1">指定</option><option value="{$p}">本页</option><option value="{$p0[2]}">末页</option><option value="0">首页</option></select><input name="p2" size="2"/><input type="submit" value="Go"/>{$p0[1]}/{$cnt}页
</form>
<form action="editsave.php?path={$_GET['path']}&amp;p=$p" method="post">
HTML;
if($_POST['go'])
 {
$len=iconv_strlen($edit['content'][$p]=form::someinput_get('content',$_POST),'utf-8');
echo '本段共',$len,'字，保存';
echo file_put_contents($fn,serialize($edit)) ? '成功' : '失败';
 }
if($_POST['save'])
 {
_editsave($edit,$_SESSION['editset'],$msg);
echo '<br/>',$msg;
 }
if($_POST['close'])
 {
unlink($fn);
echo '<br/>文件已关闭，不能继续编辑。请点击顶部的链接返回。';
 }
echo <<<HTML
<hr/><input name="save" type="submit" value="更新文件"/><input name="close" type="checkbox" value="1"/>关闭</form>
HTML;
echo <<<HTML
<div class="big_board"><div class="board_title">By：Admin@Lspecial.Com</div></div>
</body>
</html>
HTML;
?>
